<template>
	<view>
		<view class="paybox" v-if="isShow">
			<view class="paybox_title">确认付款</view>
			<view class="paybox_num">
				￥<text>{{money}}.00</text>
			</view>
			<view class="pay_mode">
				<view class="pay_mode_title">支付方式</view>
				<view class="pay_mode_item" @tap="checkZhifu">
					<view class="mode_item_left">
						<image src="../../../static/wode/zhifu.png" mode=""></image>
						<text>支付宝支付</text>
					</view>
					<image v-if="iszhifu" class="mode_item_right" src="../../../static/wode/xuanze1.png" mode=""></image>
					<image v-else class="mode_item_right" src="../../../static/wode/xuanze.png" mode=""></image>
				</view>
				<view class="pay_mode_item" @tap="checkWeixin">
					<view class="mode_item_left">
						<image src="../../../static/wode/weixin.png" mode=""></image>
						<text>微信支付</text>
					</view>
					<image v-if="isweixin" class="mode_item_right" src="../../../static/wode/xuanze1.png" mode=""></image>
					<image v-else class="mode_item_right" src="../../../static/wode/xuanze.png" mode=""></image>
				</view>
				<view class="check" @tap="check">
					<image v-if="ischeck" src="../../../static/index/theselected.png" mode=""></image>
					<image v-else src="../../../static/index/uncheck.png" mode=""></image>
					<text>我已经阅读并同意《充值协议》</text>
				</view>
				<view class="btn shurepay" v-if="ischeck" @tap="toPay">
					确认充值
				</view>
				<view class="btn mask-btn" v-else>
					确认充值
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: ["money","isShow","duration","newMember_level","paytype"],
		data() {
			return {
				ischeck:true,
				iszhifu:true,
				isweixin:false,
			};
		},
		methods: {
			check() {
				if (this.ischeck == false) {
					this.ischeck = true;
				} else {
					this.ischeck = false;
				}
			},
			checkZhifu() {
				this.iszhifu = true
				this.isweixin = false
			},
			checkWeixin() {
				this.isweixin = true
				this.iszhifu = false
			},
			// #ifdef APP-PLUS
			toPay() {
				var me = this;
				var data = {
					member_level: this.newMember_level,
					rcharge_type: this.paytype,
					user_id: uni.getStorageSync('user_id'),
					amount: this.money,
					source: 'android',
					rcharge_account: this.mobile,
					member_duration:this.duration,
				}
				if (this.iszhifu) {
					this.myAjaxNewPost({ //支付宝订单数据
						model: 'user',
						controllerName: 'pay',
						actionName: 'aliPay',
						data: data,
						successBack: function(res) {
							console.log(res)
							me.paydata = res.data.data
							toString(me.paydata)
							console.log(me.paydata)
							uni.requestPayment({
								provider: 'alipay',
								orderInfo: me.paydata, //微信、支付宝订单数据
								success: function(res) {
									console.log('success:' + JSON.stringify(res));
									me.getUserData()
								},
								fail: function(err) {
									console.log('fail:' + JSON.stringify(err));
									uni.showToast({
										title: '支付失败',
										icon: 'none'
									})
								}
							});
						}
					})
			
				} else if (this.isweixin) {
					this.myAjaxNewPost({ //微信订单数据
						model: 'user',
						controllerName: 'pay',
						actionName: 'wxPay',
						data: data,
						successBack: function(res) {
							console.log(res)
							me.paydata = res.data.data
							console.log(me.paydata)
							uni.requestPayment({
								provider: 'wxpay',
								orderInfo: me.paydata, //微信、支付宝订单数据
								success: function(res) {
									console.log('success:' + JSON.stringify(res));
								},
								fail: function(err) {
									console.log('fail:' + JSON.stringify(err));
								}
							});
						}
					})
			
			
				}
			},
			// #endif
			
		},
	}
</script>

<style scoped>
/* 支付框 */
	.paybox {
		background: #FFFFFF;
		width: 100%;
		height: 860upx;
		border: 1upx solid #E6E6E6;
		border-radius: 10upx;
		padding: 0 24upx;
		box-sizing: border-box;
		z-index: 10000;
		position: fixed;
		bottom: -90upx;
	}

	.paybox_title {
		text-align: center;
		font-size: 32upx;
		padding: 24upx 0 26upx 0;
		border-bottom: 1upx solid #E6E6E6;
	}

	.paybox_num {
		font-size: 47upx;
		color: #333333;
		text-align: center;
		padding: 30upx 0;
	}

	.paybox_num text {
		font-size: 88upx;
	}

	.pay_mode {
		font-size: 32upx;
		color: #000000;
	}

	.pay_mode_item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 88upx;
		border-bottom: 1upx solid #E6E6E6;
	}

	.pay_mode_title {
		border-bottom: 1upx solid #E6E6E6;
		width: 100%;
		padding-bottom: 20upx;
	}

	.mode_item_left {
		display: flex;
		align-items: center;
		line-height: 88upx;

	}

	.mode_item_left image {
		width: 58upx;
		height: 58upx;
		margin-right: 20upx;
	}

	.mode_item_right {
		width: 40upx;
		height: 40upx;
	}

	.check {
		padding: 30upx 0;
	}

	.check image {
		width: 26upx;
		height: 26upx;
		margin-right: 10upx;
	}

	.check text {
		font-size: 28upx;
		color: #333333;
	}

	.shurepay {
		margin-bottom: 30upx;
	}

	.mask-btn {
		width: 702upx;
		height: 88upx;
		background: rgba(70, 206, 207, .5);
		border-radius: 10upx;
		color: #FFFFFF;
		text-align: center;
		line-height: 88upx;
		margin: 0 auto;
		font-size: 32upx;
	}
</style>
